<?php

require_once('dbconnect.inc.php');

try
{
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $dbh->beginTransaction();


    $sth = $dbh->query('select * from params where name="log-rotate"');

    if ($rec = $sth->fetchAll())
    {
        $day = $rec[0]['value'];
    }
    else
    {
        die();            
    }
        
    $sth = $dbh->prepare('DELETE FROM log WHERE log_date < DATE_SUB( NOW( ) , INTERVAL :day DAY )');

    $sth->bindParam(':day', $day, PDO::PARAM_INT);

    $sth->execute();

    $dbh->commit();
}
catch (Exception $e)
{
    $dbh->rollBack();
}

?>